<?php
$wid = Session::get('wid');

/*****************7天处理数据*****************/
$m = new Model('vshop_order');
$stime = date('Y-m-d').' 23:59:59';
$etime = Getday(7);
$res = $m->field('id,payAmount,OrderStatus,PayStatus,RightsStatus')->where(array('wid'=>$wid,'create_time@>'=>$etime,'create_time@<='=>$stime))->list_all();
$w_num = 0;//下单数
$w_dellnum = 0;//成交数
$w_dynum = 0;//退单数
$w_total = 0;//总额
$w_delltotal = 0;//成交总额
$w_dytotal = 0;//退款总额
foreach($res as $_va){
	$w_num += 1;//下单数
	$w_total += $_va->payAmount;
	if(($_va->OrderStatus == 2 || $_va->OrderStatus == 0 || $_va->OrderStatus == 1) && $_va->PayStatus == 1){
		$w_dellnum += 1;
		$w_delltotal += $_va->payAmount;
	}elseif(($_va->OrderStatus == 4 || $_va->OrderStatus == 5) && ($_va->RightsStatus == 2 || $_va->RightsStatus == 5 || $_va->RightsStatus == 6)){
		$w_dynum += 1;
		$w_dytotal += $_va->payAmount;
	}
}
//返利佣金
//$n = new Model('vshop_brokerage');
//$w_yjtotal = $n->field('id,money')->where(array('wid'=>$wid,'ctime@>'=>$etime,'ctime@<='=>$stime,'money@>'=>0))->sum('money');
/*****************7天处理数据*****************/

//待发货订单
$n1 = new Model('vshop_order');
//$num1 = $n1->field('id')->where(array('wid'=>$wid,'OrderStatus'=>1,'DeliveryStatus'=>0,'PayStatus'=>1))->count();
//总交易额
$num1 = $n1->field('id,payAmount')->where(array('wid'=>$wid,'OrderStatus'=>array(0,1,2),'PayStatus'=>1))->sum('payAmount');

//待处理维权
$n2 = new Model('vshop_order');
//$num2 = $n2->field('id')->where(array('wid'=>$wid,'OrderStatus'=>array(4,5),'RightsStatus'=>array(0,1,3,4)))->count();
//总交易数
$num2 = $n2->field('id')->where(array('wid'=>$wid,'OrderStatus'=>array(0,1,2),'PayStatus'=>1))->count();

//昨日下单数
$zs_time = date('Y-m-d').' 23:59:59';
$ze_time = Getday(1);
$n3 = new Model('vshop_order');
$num3 = $n3->field('id')->where(array('wid'=>$wid,'create_time@>'=>$ze_time,'create_time@<='=>$zs_time))->count();

//昨日成交金额
$n4 = new Model('vshop_order');
$sum = $n4->field('id,payAmount')->where(array('wid'=>$wid,'OrderStatus'=>array(1,2),'PayStatus'=>1,'create_time@>'=>$ze_time,'create_time@<='=>$zs_time))->sum('payAmount');

//计算时间
function Getday($sign="0",$i=1){
    $tmp_date=date("Y-m-d");
	$fm_forward = date("Y-m-d",strtotime("$tmp_date -$sign day"));
	if($i == 1){
		$str = $fm_forward.' 00:00:00';
	}elseif($i == 2){
		$str = $fm_forward.' 23:59:59';
	}
	return $str;
}
$level_id =  Session::get('level_id');
$auth_check = new Model('auth_check');
$auth_check->find(array('auth_id'=>$level_id));
$nopages = explode(',',$auth_check->controllers);
